package com.hotel.websocketsystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.common.status.ResultMsg;
import com.common.status.StatusCode;
import com.common.utils.ResultUtils;
import com.common.utils.ResultVo;
import com.hotel.websocketsystem.pojo.CustomerServiceMessage;
import com.hotel.websocketsystem.pojo.CustomerServiceUser;
import com.hotel.websocketsystem.service.CustomerServiceMessageService;
import com.hotel.websocketsystem.service.CustomerServiceUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * (CustomerServiceUser)表控制层
 *
 * @author makejava
 * @since 2022-11-01 19:18:26
 */
@Api(value = "CustomerUserController",tags = {"客服模块"})
@RestController
@RequestMapping("customerServiceUser")
public class CustomerServiceController {

    @Resource
    private CustomerServiceUserService customerServiceUserService; // 客服用户

    @Resource
    private CustomerServiceMessageService customerServiceMessageService; // 客服消息

    @ApiOperation(value = "查询所有用户信息")
    @GetMapping("/getUserList")
    public ResultVo<List<CustomerServiceUser>> getUserList() {
        List<CustomerServiceUser> list = customerServiceUserService.list();
        if (list.size() != 0) return ResultUtils.success(ResultMsg.SUCCESS_MSG, StatusCode.SUCCESS_CODE,list);
        else return ResultUtils.error(ResultMsg.ERROR_MSG,StatusCode.SYSTEM_ERROR_CODE,null);
    }

    @ApiOperation(value = "查询所有消息信息")
    @GetMapping("/getMessageList")
    public ResultVo<List<CustomerServiceMessage>> getMessageList() {
        List<CustomerServiceMessage> list = customerServiceMessageService.list();
        if (list.size() != 0) return ResultUtils.success(ResultMsg.SUCCESS_MSG, StatusCode.SUCCESS_CODE,list);
        else return ResultUtils.error(ResultMsg.ERROR_MSG,StatusCode.SYSTEM_ERROR_CODE,null);
    }

    @ApiOperation(value = "根据用户账号查询用户信息")
    @GetMapping("/getUserInfoUserAdmin")
    public ResultVo<CustomerServiceUser> getUserInfoUserAdmin(@PathParam("userAdmin") String userAdmin){
        LambdaQueryWrapper<CustomerServiceUser> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CustomerServiceUser::getUserAdmin,userAdmin);//将传进来的用户账号与数据库中的账号做匹配
        CustomerServiceUser customerServiceUser=customerServiceUserService.getOne(lambdaQueryWrapper);
        if (customerServiceUser != null) return ResultUtils.success(ResultMsg.SUCCESS_MSG, StatusCode.SUCCESS_CODE,customerServiceUser);
        else return ResultUtils.error(ResultMsg.ERROR_MSG,StatusCode.SYSTEM_ERROR_CODE,null);
    }

    @ApiOperation(value = "根据用户账号查询用户信息")
    @GetMapping("/getUserInfoByUserAdmin")
    public ResultVo<CustomerServiceUser> getUserInfoByUserAdmin(@RequestParam String userAdmin) {
        LambdaQueryWrapper<CustomerServiceUser> ldq = new LambdaQueryWrapper<>();
        ldq.eq(CustomerServiceUser::getUserAdmin,userAdmin);
        CustomerServiceUser one = customerServiceUserService.getOne(ldq);
        if (one != null) return ResultUtils.success(ResultMsg.SUCCESS_MSG, StatusCode.SUCCESS_CODE,one);
        else return ResultUtils.error(ResultMsg.ERROR_MSG,StatusCode.SYSTEM_ERROR_CODE,null);
    }


}

